package com.akeil.flash.preferences;

import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.preferences.ScopedPreferenceStore;

import flash.Activator;

public class BaseInfoPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

	private ScopedPreferenceStore preferences;

	private StringFieldEditor companyName;
	private StringFieldEditor companyAddress;
	private StringFieldEditor companyPhone;
	private StringFieldEditor deviceInfo;
	private StringFieldEditor deviceNumber;
	private StringFieldEditor workPerson;

	public BaseInfoPreferencePage() {
		super(GRID);
		preferences = new ScopedPreferenceStore(new ConfigurationScope(), Activator.PLUGIN_ID);

		setPreferenceStore(Activator.getDefault().getPreferenceStore());
	}

	@Override
	protected void performDefaults() {
		companyName.loadDefault();
		companyAddress.loadDefault();
		companyPhone.loadDefault();
	}

	@Override
	public boolean performOk() {
		return super.performOk();
	}

	@Override
	protected void performApply() {
		IPreferenceStore preferenceStore = getPreferenceStore();

		preferenceStore.setValue(IPreferenceConstants.COMPANY_NAME, companyName.getPreferenceName());
		preferenceStore.setValue(IPreferenceConstants.COMPANY_ADDRESS, companyAddress.getPreferenceName());
		preferenceStore.setValue(IPreferenceConstants.COMPANY_PHONE, companyPhone.getPreferenceName());
		preferenceStore.setValue(IPreferenceConstants.DEVICE_INFO, deviceInfo.getPreferenceName());
		preferenceStore.setValue(IPreferenceConstants.DEVICE_NUMBER, deviceNumber.getPreferenceName());
		preferenceStore.setValue(IPreferenceConstants.WORK_PERSON, workPerson.getPreferenceName());
	}

	@Override
	public void init(IWorkbench workbench) {
		// TODO Auto-generated method stub

	}

	/**
	 * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
	 * @Function: BaseInfoPreferencePage.java
	 * @Description: 该函数的功能描述
	 *
	 * @param: 描述1描述
	 * @return: 返回结果描述
	 * @throws: 异常描述
	 *
	 * @version: v1.0.0
	 * @author: SNOW-PC
	 * @date: 2018年6月19日 上午11:26:34
	 *
	 *        Modification History: Date Author Version Description
	 *        ---------------------------------------------------------*
	 *        2018年6月19日 SNOW-PC v1.0.0 修改原因
	 */
	@Override
	protected void createFieldEditors() {
		// TODO Auto-generated method stub
		Composite parent = getFieldEditorParent();

		companyName = new StringFieldEditor(IPreferenceConstants.COMPANY_NAME, "公司名称:", parent);
		addField(companyName);
		companyAddress = new StringFieldEditor(IPreferenceConstants.COMPANY_ADDRESS, "公司地址:", parent);
		addField(companyAddress);
		companyPhone = new StringFieldEditor(IPreferenceConstants.COMPANY_PHONE, "公司电话:", parent);
		addField(companyPhone);
		deviceInfo = new StringFieldEditor(IPreferenceConstants.DEVICE_INFO, "仪器型号:", parent);
		addField(deviceInfo);
		deviceNumber = new StringFieldEditor(IPreferenceConstants.DEVICE_NUMBER, "仪器编号:", parent);
		addField(deviceNumber);
		workPerson = new StringFieldEditor(IPreferenceConstants.WORK_PERSON, "试验人员:", parent);
		addField(workPerson);
		
	}

}
